package com.definity.toolkit.web.taglib;

import javax.servlet.jsp.JspException;

public class SlideShowTag extends BaseTag {

	private static final long serialVersionUID = -5295109077599830040L;

	private String property;
	private String styleClass;
	private String url;
	private boolean stretch;
	private boolean subtitleAlwaysVisible;
	private boolean controlAlwaysVisible;
	
	public SlideShowTag() {
		setStretch(true);
	}
	
	public void setProperty(String property) {
		this.property = property;
	}
	
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}
	
	public void setUrl(String url) {
		this.url = url;
	}
	
	public void setStretch(boolean stretch) {
		this.stretch = stretch;
	}
	
	public void setSubtitleAlwaysVisible(boolean subtitle) {
		this.subtitleAlwaysVisible = subtitle;
	}
	
	public void setControlAlwaysVisible(boolean buttonAlwaysVisible) {
		this.controlAlwaysVisible = buttonAlwaysVisible;
	}
	
	@Override
	public int doStartTag() throws JspException {
		if (styleClass == null)
			styleClass = "";
		
		StringBuilder html = new StringBuilder();
		html.append("<div id=\"" + property + "\" class=\"slideshow " + styleClass + "\" url=\"" + url + "\">");
		html.append("<input type=\"hidden\" name=\"slide\" id=\"slide\" value=\"0\" />");
		html.append("<img class=\"image\" stretch=\"" + stretch + "\" />");
		
		String subtitleStyleClass = "subtitle";
		if (subtitleAlwaysVisible)
			subtitleStyleClass += " alwaysVisible";
		html.append("<div class=\"" + subtitleStyleClass + "\"></div>");
		
		String controlStyleClass = "";
		if (controlAlwaysVisible)
			controlStyleClass = " alwaysVisible";
		
		html.append("<div class=\"buttonLeft" + controlStyleClass + "\"></div>");
		html.append("<div class=\"buttonRight" + controlStyleClass + "\"></div>");
		
		write(html);
		
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {
		write("</div>");
		
		return EVAL_PAGE;
	}
	
}
